package com.xusl.spring.conn;

import com.alibaba.druid.pool.DruidPooledConnection;
import com.xusl.spring.utils.DruidUtils;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @Author: xusl
 * @Date: 2021/8/4 10:46 下午
 */
public class JdbcConnection {

    private ThreadLocal<Connection> threadLocal = new ThreadLocal<>();


    public Connection getConnection() throws SQLException {
        Connection connection = threadLocal.get();

        if (connection == null) {
            connection = DruidUtils.getInstance().getConnection();

            threadLocal.set(connection);
        }

        return connection;
    }
}
